package spring5.testdemo;

import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import spring5.Book;
import spring5.Orders;
import spring5.User;

public class TestSpring5 {

    //创建对象测试
    @Test
    public void testAdd() {
        //1、加载Spring配置文件
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        //2、获取配置文件的对象
        User user = context.getBean("user", User.class);

        System.out.println(user);
        user.add();
    }

    //set注入属性测试
    @Test
    public void testBook() {
        //1、加载Spring配置文件
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        //2、获取配置文件的对象
        Book book = context.getBean("book", Book.class);

        System.out.println(book);
        book.testDemo();
    }

    //有参构造注入属性测试
    @Test
    public void testOrders() {
        //1、加载Spring配置文件
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        //2、获取配置文件的对象
        Orders order = context.getBean("orders", Orders.class);

        System.out.println(order);
        order.testOrder();
    }

    //p名称空间注入
    @Test
    public void testBook2() {
        //1、加载Spring配置文件
        ApplicationContext context = new ClassPathXmlApplicationContext("bean1.xml");
        //2、获取配置文件的对象
        Book book = context.getBean("book", Book.class);

        System.out.println(book);
        book.testDemo();
    }
}
